const upgradePackage = require("./upgradePackage");
const { log } = require("../utils");
const configLang = require("../configLang");
const t = require("../../config/dict");
const configSource = require("../configSource");
const version = require("../base/version");
const next = (context) => {
  configSource(context).then((context) => {
    upgradePackage(context)
      .then(() => {})
      .catch((err) => {
        log("error", {
          message: err.message,
        });
      });
  });
};

module.exports = (packageName, options) => {
  const { update } = options || {};
  configLang({ lang: "english" }, (context) => {
    //version(context).then((context) => {
    packageName = update
      ? [packageName, "@^", update].join("")
      : [packageName, "@latest"].join("");
    context.metadata = {
      projectUpdateDepend: packageName,
    };
    log("info", { message: [packageName].join(" ") });
    next(context);
    //});
  });
};
